package Syntax;

public class Symbol {
    private String type;//要么是 NonTerminal 非终结符 要么是 Terminal 终结符
    private String content;

    public Symbol(){}
    public Symbol(String type, String content) {
        this.type = type;
        this.content = content;
    }

    public Symbol(Symbol new_sym)
    {
        this.type = new_sym.getType();
        this.content = new_sym.getContent();
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public boolean isTerminal(){
        if( type.equals("Terminal") )
            return  true;
        else
            return  false;
    }

    public boolean isNonTerminal(){
        if( type.equals("NonTerminal") )
            return true;
        else
            return  false;
    }

    public boolean equals(Object obj)//重新 equals（Object）函数 供list.contains调用
    {
        if( obj instanceof  Symbol)
        {
            if(  ((Symbol)obj).getType().equals(this.type) && ((Symbol)obj).getContent().equals(this.content) )
                return true;
        }
        return false;
    }

    public int hashCode()
    {
        return  this.content.hashCode();
    }
}
